<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    .minyuan_red{padding: 4px;background-color: red;border-radius: 50%;font-size: 0;margin-right: 6px;position: relative;top: -4px;}
    .minyuan_lv{padding: 4px;background-color: #19BE6B;border-radius: 50%;font-size: 0;margin-right: 6px;position: relative;top: -4px;}
    .layui-table tr td .laytp-tree-table-cell > .laytp-tree-table-cell-content{
        font-size: 13px;
    }
</style>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <div id="enginid" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">年度：</label>
                        <div class="layui-input-block">
                            <select id="year" name="year" lay-filter="year">
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var year=(new Date).getFullYear();
    year = parseInt(year);

    var yearStr = '';
    for (var i=year; i>=year-10; i--){
        yearStr += '<option value="'+i+'">'+i+'</option>';
    }
    $("#year").html(yearStr);

    var currButAuth, currButAuthArr=[], currTabData, mytable, form;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable', 'treeTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable, treeTable=layui.treeTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('项目管理费成本分析', 2);
        mytable = treeTable.render({
            elem: "#datalist",id: "datalist",title: "管理费成本分析"
            ,url: facade.url(ask_cheng_guan_tong),where: {year:year}, page: false, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            , tree: {
                iconIndex: 1        // 折叠图标显示在第几列
                , arrowType: 'arrow2'   // 自定义箭头风格
                , getIcon: function (d) {  // 自定义图标
                    // d是当前行的数据
                    if (d.children && d.children.length > 0) {  // 判断是否有子集
                        return '<i class="laytp-tree-icon laytp-tree-icon-folder"></i>';
                    } else {
                        return '<i class="laytp-tree-icon laytp-tree-icon-file"></i>';
                    }
                }
            }
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                for (var key in currButAuth ) {
                    currButAuthArr.push(currButAuth[key].butname);
                }
                tableButShow(currButAuth);


                xmselect_dan('enginid', res.data.enginid, res.data.is_enginid, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{field: 'name', title: '费用科目',width:300}
                ,{field:'bgmoney',title:'预算金额',align:'right',templet: function(d){return parseFormatNum(d.bgmoney) }}
                ,{field:'zhimoney',title:'支出总额',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+',0,0)">'+parseFormatNum(d.zhimoney)+'</span>';
                    }}
                ,{field: 'year', title: '搜索年度'}
                ,{field:'zhiyear',title:'年度合计',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',0)">'+parseFormatNum(d.zhiyear)+'</span>';
                    }}
                ,{field:'zhi1',title:'一月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',1)">'+parseFormatNum(d.zhi1)+'</span>';
                    }}
                ,{field:'zhi2',title:'二月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',2)">'+parseFormatNum(d.zhi2)+'</span>';
                    }}
                ,{field:'zhi3',title:'三月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',3)">'+parseFormatNum(d.zhi3)+'</span>';
                    }}
                ,{field:'zhi4',title:'四月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',4)">'+parseFormatNum(d.zhi4)+'</span>';
                    }}
                ,{field:'zhi5',title:'五月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',5)">'+parseFormatNum(d.zhi5)+'</span>';
                    }}
                ,{field:'zhi6',title:'六月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',6)">'+parseFormatNum(d.zhi6)+'</span>';
                    }}
                ,{field:'zhi7',title:'七月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',7)">'+parseFormatNum(d.zhi7)+'</span>';
                    }}
                ,{field:'zhi8',title:'八月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',8)">'+parseFormatNum(d.zhi8)+'</span>';
                    }}
                ,{field:'zhi9',title:'九月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',9)">'+parseFormatNum(d.zhi9)+'</span>';
                    }}
                ,{field:'zhi10',title:'十月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',10)">'+parseFormatNum(d.zhi10)+'</span>';
                    }}
                ,{field:'zhi11',title:'十一月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',11)">'+parseFormatNum(d.zhi11)+'</span>';
                    }}
                ,{field:'zhi12',title:'十二月',align:'right',templet: function(d){
                        return '<span class="colorlan" onclick="mingxi('+d.id+','+d.enginid+','+d.year+',12)">'+parseFormatNum(d.zhi12)+'</span>';
                    }}
            ]]
            , done: function (res) {
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
            }
        });

        listTableSearch(form, table);
    });




    function mingxi(budid, enginid, year, month) {
        openPage('./mingxi.php?budid='+budid+'&enginid='+enginid+'&year='+year+'&month='+month, '80%', '80%');
    }




    function searchTableFunc(form, table) {
        var data = form.val('TableSearchForm');
        mytable.reload('datalist', {
            where: data
        });
    }


</script>
</body>
</html>
